#include <stdio.h>
#include <sys/select.h>
#include <stdlib.h>
#include <termios.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h> /* close */
#include <string.h> 
#include <assert.h> 


int main ()
{
    int keyboard;
    int ret,i;
    char c;
    fd_set readfd;
    struct timeval timeout;
    keyboard = open("/dev/tty",O_RDONLY | O_NONBLOCK);
    assert(keyboard>0);

	timeout.tv_sec = 10;
	timeout.tv_usec =10 ;
	FD_ZERO(&readfd);
	FD_SET(keyboard,&readfd);

	while(1) {
		ret=select(keyboard+1,&readfd,NULL,NULL,NULL);
		if (ret == 0)
			printf("!\n");
		if(FD_ISSET(keyboard,&readfd))
		{
			i=read(keyboard,&c,1);
			if('\n'==c) {
				continue;
			}
			printf("input is %c\n",c);
			if ('q'==c) {
				break;
			}
		}
	}
}
